//
//  OIEmulator.h
//  OrchIDE
//
//  Created by local22 on 8/13/07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "emulator.h"

extern NSString *OIEmulatorDidWriteMemoryNotificationName;

@interface OIEmulator : NSObject <NSCoding> {
	machine_t _machine;
	int32_t _cyclesPerRTCTick;
	
	id _serialPortDelegate;
	struct state *_currentState;
}

- (void)encodeWithCoder:(NSCoder *)aCoder;
- (id)initWithCoder:(NSCoder *)aDecoder;

#pragma mark Actions
- (void)step;
- (void)stepCycles:(int)cycles;

- (BOOL)canUnstep;
- (void)unstep;

- (void)bigRedButton;

#pragma mark Accessors
- (int16_t)valueAtPhysicalAddress:(int32_t)address;
- (void)setValue:(int16_t)value atPhysicalAddress:(int32_t)address;

#pragma mark Registers
- (int16_t)r0;
- (void)setR0:(int16_t)value;

- (int16_t)r1;
- (void)setR1:(int16_t)value;

- (int16_t)r2;
- (void)setR2:(int16_t)value;

- (int16_t)r3;
- (void)setR3:(int16_t)value;

- (int16_t)r4;
- (void)setR4:(int16_t)value;

- (int16_t)r5;
- (void)setR5:(int16_t)value;

- (int16_t)r6;
- (void)setR6:(int16_t)value;

- (int16_t)r7;
- (void)setR7:(int16_t)value;

- (BOOL)isUserMode;
- (void)setUserMode:(BOOL)flag;

- (BOOL)isFlag;
- (void)setFlag:(BOOL)flag;

- (BOOL)isExecuting;
- (void)setExecuting:(BOOL)flag;

- (int16_t)rSerial;
- (void)setRSerial:(int16_t)value;

- (int16_t)instruction;
- (void)setInstruction:(int16_t)value;

- (int16_t)exceptionState;
- (void)setExceptionState:(int16_t)value;

#pragma mark Serial port
- (void)setSerialPortDelegate:(id)delegate;
- (void)writeByteToSerialPort:(uint8_t)byte;
@end

@interface NSObject (OIEmulatorSerialPortDelegate)
- (void)emulator:(OIEmulator *)emulator didReadByteFromSerialPort:(uint8_t)byte;
@end